#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int l = 0, r = 0;
        int cnt = 0;
        int n = nums.size();
        while (r < n)
        {
            if (nums[r] == 0) cnt++;
            if (cnt > k)
            {
                if (nums[l] == 0) cnt--;
                l++;
            }
            r++;
        }
        return n - l;
    }
};